package com.cloud.punish.workflow.handler.common;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import com.cloud.punish.workflow.command.WfRequest;
import com.cloud.punish.workflow.command.WfResponse;
import com.cloud.punish.workflow.handler.BeforeHandler;

/**
 * 前置sql执行器
 * 
 * @author taominglong
 *
 */
public class SqlExecutorBeforeHandler extends BeforeHandler {
	private String sql;

	public SqlExecutorBeforeHandler(String sql) {
		super();
		this.sql = sql;
	}

	@Override
	public void beforeHandler(WfRequest request, WfResponse resp, ApplicationContext context) {
		if (!StringUtils.isEmpty(sql)) {
			JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
			jdbcTemplate.execute(sql);
		}
	}

}
